import { defHttp } from '/@/utils/http/axios'
import { SerialOption } from './model/serialPort'

import { ErrorMessageMode } from '/#/axios'

enum Api {
  ListAll = '/serialPort/list',
  ListOpen = '/serialPort/listOpen',
  Open = '/serialPort/open',
  Close = '/serialPort/close/',
  GetSerialOption = '/serialPort/get',
}

/**
 * @description: 获取所有串口列表
 */
export function ListAllApi(mode: ErrorMessageMode = 'modal') {
  return defHttp.get<Array<SerialOption>>(
    {
      url: Api.ListAll,
    },
    {
      errorMessageMode: mode,
    },
  )
}

/**
 * @description: 获取已打开的串口列表
 */
export function ListOpenApi(mode: ErrorMessageMode = 'modal') {
  return defHttp.get<Array<SerialOption>>(
    {
      url: Api.ListOpen,
    },
    {
      errorMessageMode: mode,
    },
  )
}

/**
 * @description: 获取所有串口列表
 */
export function OpenApi(params: SerialOption, mode: ErrorMessageMode = 'modal') {
  return defHttp.put<boolean>(
    {
      url: Api.Open,
      params,
    },
    {
      errorMessageMode: mode,
    },
  )
}

/**
 * @description: 获取所有串口列表
 */
export function CloseApi(params: string, mode: ErrorMessageMode = 'modal') {
  return defHttp.put<boolean>(
    {
      url: Api.Close,
      params,
    },
    {
      errorMessageMode: mode,
    },
  )
}

/**
 * @description: 获取所有串口列表
 */
export function GetSerialOptionApi(mode: ErrorMessageMode = 'modal') {
  return defHttp.get<SerialOption>(
    {
      url: Api.GetSerialOption,
    },
    {
      errorMessageMode: mode,
    },
  )
}
